package virtualTabletop;

import java.util.Random;

/**
 * Making dice.
 * 
 * @author bjo013
 * 
 */
public class Die
{
	Random generator = new Random();
	int sides;

	static public Die d4 = new Die(4);
	static public Die d6 = new Die(6);
	static public Die d8 = new Die(8);
	static public Die d10 = new Die(10);
	static public Die d12 = new Die(12);
	static public Die d20 = new Die(20);
	static public Die d100 = new Die(100);

	/**
	 * constructs a die.
	 * 
	 * @param sides
	 *            number of sides on the die.
	 */
	Die(int sides)
	{
		this.sides = sides;
	}

	/**
	 * rolls a die
	 * 
	 * @return outcome of the roll
	 */
	public int roll()
	{
		return generator.nextInt(sides) + 1;
	}

	/**
	 * rolls a die x times
	 * 
	 * @param x
	 *            number of times to roll
	 * @return the final sum of the roll
	 */
	public int rollTimes(int x)
	{
		if (x <= 0)
		{
			return 0;
		}
		--x;
		return roll() + rollTimes(x);

	}

	@Override
	public String toString()
	{
		return "d" + sides;
	}

}
